const mysql = require('../config/db')
const { DataTypes } = require('sequelize')
require('dotenv').config()

const ArticleSubscription = mysql.define(
  'article_subscription',
  {
    id: {
      type: DataTypes.BIGINT,
      primaryKey: true,
      autoIncrement: true,
    },
    email: {
      type: DataTypes.STRING,
      allowNull: false,
      comment: '邮箱',
    },
    createdAt: {
      type: DataTypes.DATE,
      allowNull: false,
      defaultValue: DataTypes.NOW,
      comment: '创建时间',
    },
    updatedAt: {
      type: DataTypes.DATE,
      allowNull: false,
      defaultValue: DataTypes.NOW,
      comment: '更新时间',
    },
    unsubscribe_token: {
      type: DataTypes.CHAR(32),
      allowNull: false,
      comment: '取消订阅token',
    },
    deletedAt: {
      type: DataTypes.DATE,
      allowNull: true,
    },
  },
  {
    timestamps: true,
    createdAt: 'createdAt',
    paranoid: true,
    deletedAt: process.env['DELETED_AT'],
  },
)

module.exports = ArticleSubscription
